/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * Portions created by the Initial Developer are
 * Copyright (C) 2012 the Initial Developer.
 * All Rights Reserved.
 *
 * The Original Code is this.
 *
 * The Initial Developer of the Original Code is the author below.
 */
/**
 * @file MessageEvent.h
 * @brief Message events.
 * @author K.Ozaki
 * @date 2011/03/11
 */

#ifndef MESSAGEEVENT_H_
#define MESSAGEEVENT_H_

#include "semi/posix/MessageTimer.h"
#include "semi/logg/Logger.h"

namespace semi {

class MessageParam {
public:
    //    MessageParam(std::string taskID);
    MessageParam();
    ~MessageParam();
    //    std::string taskid;
    std::string message;
    posix::MessageTimer* timer;
    //    int sleep;
    //    posix::SignalAction* action;
};

/**
 * @brief Message events.
 *
 * @date 2011/12/21
 */
class MessageEvent {
public:

    MessageEvent();
    MessageEvent(std::string task_id);
    ~MessageEvent();

    void init(std::string task_id);
    void sendMessage(std::string message);
    void reserveMessage(int sleepsec, std::string message);

    std::string waitMessage();

    int cancelMessage();
    //    void terminate();

private:

    std::string taskId;

    // pthread_t tid;

    //    struct MessageParam {
    //        std::string message;
    //        posix::MessageTimer* timer;
    //    };

    posix::MessageQue* quep;
    posix::MessageTimer* tmrp;
    logg::Logger logr;

    //    MessageParam* param;

    void waitChild();
    //    bool sweepTimer();
    //    int getWaitCount();
    static void * threadingProcess(void* param);

    //    semi::util::Ints pidList;
    //    int currentChildPid;
    //    static posix::MessageTimer* CurrentTimer;
};

}

#endif /* MESSAGEEVENT_H_ */
